/**
 * RoleDAO class.
 */
package pits.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import pits.dto.RoleDTO;
import pits.util.Constants;

/**
 * @author ltd
 * 
 */
public class RoleDAO {

	Logger log = Logger.getLogger("RoleDAO");

	public List<RoleDTO> getRoles() {

		log.info("RoleDAO.getRoles start");

		List<RoleDTO> result = new ArrayList<RoleDTO>();
		RoleDTO dto = null;
		Connection conn = null;
		String query = Constants.BLANK_VALUE;
		ResultSet rs = null;
		PreparedStatement pStat = null;

		try {
			query = "select * from role where isDeleted=0";
			conn = pits.util.Connection.getConnection();
			pStat = conn.prepareStatement(query);
			rs = pStat.executeQuery();
			while (rs.next()) {
				dto = new RoleDTO();
				dto.setRole(rs.getString("Role"));
				dto.setRoleID(rs.getInt("RoleID"));
				result.add(dto);
			}

		} catch (Exception sqlEx) {
			log.error("RoleDAO.getRoles: " + sqlEx);
		} finally {
			try {
				rs.close();
				pStat.close();
				conn.close();
			} catch (SQLException sqlEx) {
				log.error("RoleDAO.getRoles: " + sqlEx);
			}
		}

		return result;
	}
}
